package com.qiwx.pigeon.activity.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.activity.query.LayEggRecordActivity;
import com.qiwx.pigeon.base.BaseMVPActivity;
import com.qiwx.pigeon.data.params.SearchParam;
import com.qiwx.pigeon.data.vo.EggLoseBean;
import com.qiwx.pigeon.data.vo.LayEggAmountBean;
import com.qiwx.pigeon.data.vo.QueryCageBean;
import com.qiwx.pigeon.data.vo.QueryFertilizedBean;
import com.qiwx.pigeon.data.vo.CageProduceBean;
import com.qiwx.pigeon.data.vo.SummaryOther;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.presenter.QueryCagePresenter;
import com.qiwx.pigeon.viewinterface.IQueryCageView;
import com.qiwx.pigeon.widget.ArrowView;

import java.lang.ref.WeakReference;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @description
 * @Author qiwx
 * @Date 2020-04-07 22:08
 * 鸽笼详情
 **/
public class CageDetailActivity extends BaseMVPActivity<IQueryCageView, QueryCagePresenter> implements IQueryCageView {
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_return)
    ArrowView titleReturn;
    @BindView(R.id.llTitle)
    LinearLayout llTitle;
    @BindView(R.id.txt_date)
    TextView txtDate;
    @BindView(R.id.txt_number_title)
    TextView txtNumberTitle;
    @BindView(R.id.txt_number)
    TextView txtNumber;
    @BindView(R.id.layEggAmount)
    TextView layEggAmount;
    @BindView(R.id.btn_eliminate)
    Button btnEliminate;
    @BindView(R.id.wujing2)
    TextView wujing2;
    @BindView(R.id.sijing2)
    TextView sijing2;
    @BindView(R.id.shoujing2)
    TextView shoujing2;
    @BindView(R.id.wudan)
    TextView wudan;
    @BindView(R.id.shoujing2wujing1)
    TextView shoujing2wujing1;
    @BindView(R.id.shoujing2sijing1)
    TextView shoujing2sijing1;
    @BindView(R.id.lin_root)
    LinearLayout linRoot;
    @BindView(R.id.bad_egg)
    TextView badEgg;
    @BindView(R.id.bfd2cpd)
    TextView bfd2cpd;
    @BindView(R.id.egg_amount1)
    TextView eggAmount1;
    @BindView(R.id.egg_amount2)
    TextView eggAmount2;
    @BindView(R.id.death_amount)
    TextView deathAmount;
    @BindView(R.id.wujing2sijing1)
    TextView wujing2sijing1;
    @BindView(R.id.shoujing1)
    TextView shoujing1;
    @BindView(R.id.wujing1)
    TextView wujing1;
    @BindView(R.id.sijing1)
    TextView sijing1;
    @BindView(R.id.btn_lay_egg_record)
    Button btnLayEggRecord;
    CageProduceBean queryCageBean;
    int c_id;


    @Override
    public int getLayoutId() {
        return R.layout.activity_cage_detail;
    }

    @Override
    public void initAfterOnCreate() {
        c_id = getIntent().getIntExtra("c_id", 0);
        initView();
        loadData();
    }

    private void initView() {
        titleContent.setText("鸽笼生产详情表");
        titleReturn.changeArrowLeft();
        btnEliminate.setVisibility(View.INVISIBLE);
        btnEliminate.setWidth(1);

    }

    private void loadData() {
//        QueryCageParam param = new QueryCageParam();
//        param.setC_id(c_id);
        SearchParam param = new SearchParam();
        param.setC_id(c_id);
        mPresenter.searchCage(param);
    }


    @OnClick({R.id.title_return, R.id.btn_lay_egg_record})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_return:
                finish();
                break;
            case R.id.btn_lay_egg_record:
                if (queryCageBean != null) {
                    checkLayEggRecord(queryCageBean);
                }
                break;
        }
    }

    public void checkLayEggRecord(CageProduceBean bean) {
        Intent go = new Intent(this, LayEggRecordActivity.class);
        go.putExtra("c_id", bean.getC_id());
        go.putExtra("c_number", bean.getC_number());
        startActivity(go);

    }

    @Override
    public QueryCagePresenter createPresenter() {
        return new QueryCagePresenter(new WeakReference(this));
    }

    @Override
    public void onSearchSuccess(CageProduceBean bean) {
        if (bean == null)
            return;
        this.queryCageBean = bean;
        txtDate.setText(bean.getCage_date());
        txtNumber.setText("" + bean.getC_number() + "");
        layEggAmount.setText("" + bean.getLayEggAmount() + "");
        eggAmount1.setText("" + bean.getEggAmount1());
        eggAmount2.setText("" + bean.getEggAmount2());
        wujing2.setText("" + bean.getWujing2());
        shoujing2.setText("" + bean.getShoujing2() + "");
        sijing2.setText("" + bean.getSijing2());
        shoujing2sijing1.setText("" + bean.getShoujing2sijing1());
        shoujing2wujing1.setText("" + bean.getShoujing2wujing1());
        wujing2sijing1.setText("" + bean.getWujing2sijing1());
        shoujing1.setText("" + bean.getShoujing1());
        sijing1.setText("" + bean.getSijing1());
        wujing1.setText("" + bean.getWujing1());
        bfd2cpd.setText("" + (bean.getFd_breaken()
                + bean.getYd_breaken()
                + bean.getCd_breaken()
                + bean.getCz_breaken()));
        wudan.setText("" + (bean.getYd_wd()
                + bean.getFd_wd()
                + bean.getCd_wd()
                + bean.getCz_wdwz())
        );
        badEgg.setText("" + (bean.getYd_bad()
                + bean.getFd_bad()
                + bean.getCd_bad()
                + bean.getCz_bad()));
    }

    @Override
    public void onQueryCageSuccess(PageInfo<CageProduceBean> bean) {

    }


    @Override
    public void onQueryLayEggSuccess(List<LayEggAmountBean> data) {

    }

    @Override
    public void onQueryEggLoseSuccess(List<EggLoseBean> data) {

    }

    @Override
    public void onQueryShoujSuccess(List<QueryFertilizedBean> data) {

    }

    @Override
    public void onQueryOtherSuccess(List<SummaryOther> data) {

    }

    @Override
    public void onAddCageEliminateSuccess(int type) {

    }

    @Override
    public void onFailure(String error) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
